package pub.cleangao.mybatis.expression;

import lombok.Setter;

@Setter
public class NullExpression implements WhereExpressionValue {


    private WhereJoint whereJoint;
    private String column;
    private int index;
    private boolean nil;

    public static WhereExpression buildExpression(WhereJoint whereJoint, String columnName, boolean nil, int... index) {
        NullExpression nullExpression = new NullExpression();
        nullExpression.setWhereJoint(whereJoint);
        nullExpression.setColumn(columnName);
        nullExpression.setNil(nil);
        if (index != null && index.length > 0) {
            nullExpression.setIndex(index[0]);
        }
        return nullExpression;
    }

    @Override
    public WhereJoint joint() {
        return whereJoint;
    }

    @Override
    public String column() {
        return column;
    }

    @Override
    public Object targetValue() {
        return "";
    }

    @Override
    public WhereOperator operator() {
        return nil ? WhereOperator.nil : WhereOperator.notNil;
    }


    @Override
    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public int index() {
        return index;
    }


    @Override
    public WhereExpressionType type() {
        return WhereExpressionType.VALUE;
    }
}
